// 判断用户名
    function judgeUser(user){
        userFlag = false;
        var userReg = /^[a-zA-Z$_][\w$]{5,11}$/;
        var p = new Promise((resolve,reject) => {
            if (userReg.test(user) ) {
                isExistUser({user}).then((result) => {
                    if(result.status) {
                        resolve(result);
                    } else {
                        reject(result);
                    }
                })
            } else {
                reject({
                    status:false,
                    msg:"用户名由数字,字母,下划线,$组成，6~12位,不能以数字开头"
                })
            }
        })
        return p;
    }
// 判断手机号
    function judgePhone(phone){
        phoneFlag = false;
        // var phone = phoneInp.value;
        var phoneReg = /^1[3456789][\d]{9}$/;
        var p = new Promise((resolve,reject) => {
            if (phoneReg.test(phone) ) {
                isExistPhone({phone}).then((result) => {
                    if(result.status) {
                        resolve(result);
                    } else {
                        reject(result);
                    }
                })
            } else {
                reject({
                    status:false,
                    msg:"请输入正确的手机号",
                })
            }
        })
        return p;
    }
// 判断邮箱
    function judgeEmail(email){
        emailFlag = false;
        var emailReg = /^\w{6,18}@\w+\.com$/;
        var p = new Promise((resolve,reject) => {
            if (emailReg.test(email) ) {
                isExistEmail({email}).then((result) => {
                    if(result.status) {
                        resolve(result);
                    } else {
                       reject(result);
                    }
                });
            } else {
                reject({
                    status:false,
                    msg:"请输入正确的邮箱",
                })
            }
        })
        return p;
    }
// 判断密码
    function judgePwd(pwd){
        var pwdReg = /^[\w$]{6,12}$/;
        if (pwdReg.test(pwd) ) {
            //  判断密码强度
            var numFlag = false;     //假设不存在数字
            var bigFlag = false;     //假设不存在大写字母
            var smallFlag = false;   //假设不存在小写字母
            var speFlag = false;     //假设不存在特殊字符
            
            var numReg = /[0-9]/;                 
            var bigReg = /[A-Z]/;     
            var smallReg = /[a-z]/;   
            var speReg = /[_$]/;

            if (numReg.test(pwd))   numFlag = true;     //验证存在数字
            if (bigReg.test(pwd))  bigFlag = true;     //验证存在大写字母
            if (smallReg.test(pwd))   smallFlag = true;   //验证存小写字母
            if (speReg.test(pwd))    speFlag = true;      //验证存在特殊字符  

            var sum = numFlag + bigFlag + smallFlag + speFlag; 
            switch(sum) {
                case 1: 
                    msg = "密码强度弱";
                    break;
                case 2: 
                    msg = "密码强度中";
                    break;
                case 3: 
                    msg = "密码强度强";
                    break;
                case 4: 
                    msg = "密码强度超强";
                    break;    
            }
            return Promise.resolve({
                msg,
                status:true,
            });
        } else {
            return Promise.reject({
                msg:"密码6至12位的数字,大小写字母,_,$ 组成",
                status:false,
            });
        }
    }
// 判断验证码
    function judgeCode(code,_rand) {
        var codeReg = new RegExp(_rand,"i");
        if (codeReg.test(code) ) {
            return Promise.resolve({
                msg:"√",
            })
        } else {
            return Promise.reject({
                msg:"×"
            })
            
        }
    }